﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 图片分类
{
    public partial class Form1 : Form
    {
        Random r;
        int left;
        int moveStep;
        int score;
        int picNum;

        public Form1()
        {
            InitializeComponent();
            r = new Random(); //随机数生成器
            left = pictureBox1.Left; //照片初始位置
            moveStep = 5;
            score = 0;
            picNum = 0;

            newPicture();
        }

        private void newPicture() //更换图片，重置位置
        {
            int picnum = r.Next(0, 8);
            picNum = picnum;
            string filename = @"D:\\pic\\" + picnum.ToString() + ".jpg";
            pictureBox1.Image = Image.FromFile(filename);

            pictureBox1.Left = left;

            if (progressBar1.Value >= 9)
            {
                score_label.Text = "得分：" + score.ToString();
                timer1.Enabled = false;
                score_label.Visible = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (pictureBox1.Right < this.ClientRectangle.Width)
            {
                pictureBox1.Left += moveStep;
            }
            else //开始新题，更换图片，初始位置
            {
                newPicture();
                if(progressBar1.Value < 10)
                {
                    progressBar1.Value++;
                }
                
                
            }
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            switch (trackBar1.Value)
            {
                case (0):moveStep = 5;break;
                case (1):moveStep = 10;break;
                case (2):moveStep = 15;break;
                case (3):moveStep = 20;break;
            }
            progressBar1.Value = 0;
            score = 0;
            pictureBox1.Left = left;
            score_label.Visible = false;
            timer1.Enabled = true;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (listBox1.SelectedIndex)
            {
                case (0):
                    if (picNum == 0 || picNum == 1) score++;
                    break;
                case (1):
                    if (picNum == 2 || picNum == 3) score++;
                    break;
                case (2):
                    if (picNum == 4 || picNum == 5) score++;
                    break;
                case (3):
                    if (picNum == 6 || picNum == 7) score++;
                    break;
                default:break;
            }
            
            newPicture();
            if (progressBar1.Value < 10)
            {
                progressBar1.Value++;
            }
           
        }
    }
}
